<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="description" content="对网页的一段概括性描述" />
<meta name="keywords" content="关键字1,关键字2,关键字3..." />
<meta name="renderer" content="webkit">
<title>迷你酥 - 企业后台管理</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" href="<%=request.getContextPath() %>/static/comm/plugin/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="<%=request.getContextPath() %>/static/comm/plugin/toastr/toastr.css"/>
<link rel="stylesheet" href="/hiring_git/static/talent/css/homepage.css">
</head>
<body>
	<header class="global">
		<div class="header">
			<a style="margin-top: 0" href="/hiring_git/TalentServlet?act=goHome"
				class="logo"> <img src="/hiring_git/static/comm/image/logo.png"
				width="139" height="60">
			</a>
			<p class="loginfo">
				欢迎您：${company.name } <a
					href="<%=request.getContextPath() %>/PositionServlet?command=list"
					style="color: blue">招聘主页</a> <a
					href="<%=request.getContextPath() %>/CompanyServlet?command=show"
					style="color: blue">企业资料</a> <a
					href="<%=request.getContextPath() %>/CompanyServlet?command=logout"
					style="color: blue">系统注销</a>
			</p>
		</div>
	</header>
	<center style="margin-top:20px;">
		<h1>企业主页</h1>
	</center>
	<hr>
	<div class="container">
		<table class="table">
			<caption>
				<strong>一、职位管理：</strong><a
					href="<%=request.getContextPath()%>/PositionServlet?command=toPositionAdd">发布职位</a>
			</caption>
			<thead>
				<tr>
					<th>编号</th>
					<th>职位名称</th>
					<th>薪资范围</th>
					<th>发布时间</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${positionList }" var="position" varStatus="v">
					<tr>
						<th scope="row">${v.count }</th>
						<td><a
							href="<%=request.getContextPath()%>/PositionServlet?command=preupdate&id=${position.id}">${position.name }</a></td>
						<td>${position.salary1 }-${position.salary2 }</td>
						<td><fmt:formatDate value="${position.releaseTime }"
								pattern="yyyy-MM-dd HH:mm:ss" /></td>
						<td><a href="javascript:void(0)" onclick="del(this, ${position.id})">删除</a></td>
					</tr>
				</c:forEach>
			</tbody>
       </table>
			
	  <table class="table">
		<caption>
			<strong>二、审核管理：</strong>
		</caption>
		<thead>
			<tr>
				<td colspan="7">
					<form id="conditionForm" action="<%=request.getContextPath() %>/ApplicationServlet?command=listCompanyVerifyByPage" method="post">
						职位名称：<input type="text" name="positionName" value="${applicationCondition.position$name }">
						审核状态：<select name="status">
									<option value="">-全部-</option>
									<option value="1" <c:if test="${applicationCondition.status == 1}">selected=selected</c:if>>待审核</option>
									<option value="2" <c:if test="${applicationCondition.status == 2}">selected=selected</c:if>>已通过</option>
									<option value="3" <c:if test="${applicationCondition.status == 3}">selected=selected</c:if>>已拒绝</option>
								</select>
						申请时间(起止)：
						<%-- <input type="text" name="appTimeStart" value="${application.appTimeStart}"/>-<input type="text" name="appTimeEnd" value="${application.appTimeEnd}"/> --%>		
						<input
			id="appTimeStart" name="appTimeStart"class="Wdate" type="text"
			onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'appTimeEnd\')||\'2020-10-01\'}', dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="${ application.appTimeStart}" />
		- <input id="appTimeEnd" class="Wdate" type="text"
			name="appTimeEnd" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'appTimeStart\')}',maxDate:'2020-10-01', dateFmt:'yyyy-MM-dd HH:mm:ss'})"  value="${ application.appTimeEnd}"/>
						
						<button>查询</button>
					</form>
				</td>
			</tr>
			<tr>
				<th>编号</th>
				<th>职位名称</th>
				<th>求职者</th>
				<th>简历信息</th>
				<th>申请时间</th>
				<th>审核状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${pageModel.list }" var="application" varStatus="v">
				<tr>
					<th scope="row">${v.count }</th>
					<td>${application.position$name }</td>
					<td><a href="javascript:void(0)">${application.talent$name }</a></td>
					<td><a href="javascript:void(0)">${application.resume$intention }</a></td>
					<td><fmt:formatDate value="${application.appTime }"
							pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td>
						<c:if test="${application.status == 1 }">
							${application.statusStr }
						</c:if>
						<c:if test="${application.status != 1 }">
							${application.statusStr }
							(<fmt:formatDate value="${application.handleTime }" pattern="yyyy-MM-dd HH:mm:ss" />)
						</c:if>
						
						<%--  jstl-> if 
				          <c:if test="${application.status == 1 }">
				          		待审核
				          </c:if>
				          <c:if test="${application.status == 2 }">
				          		审核通过
				          </c:if>
				          <c:if test="${application.status == 3 }">
				          		已拒绝
				          </c:if>
				           --%> 
				           
				      <%--  jstl-> if...else
				          <c:choose>
							<c:when test="${application.status == 1 }">
				           	 	  待审核
				           	  </c:when>
							<c:otherwise>
								<c:when test="${application.status == 2 }">
					           	 	 审核通过
					           	  </c:when>
								<c:otherwise>
					           	  	 已拒绝
					           	  </c:otherwise>
							</c:otherwise>
						</c:choose>
					  --%>
					</td>
					<td><a
						href="javascript:verify(${application.id }, ${pageModel.pageNo });">审核</a></td>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="7" align="right">
					<a href="javascript:submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerifyByPage&pageNo=${pageModel.first}')">首页</a>&nbsp;
					<a href="javascript:submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerifyByPage&pageNo=${pageModel.pre}')">上一页</a>&nbsp;
					第<select onchange="goPage(this)">
					 	<script>
					 		var pageNo = '${pageModel.pageNo }';
					 		var totalPage = '${pageModel.totalPage }';
					 		for (var i = 1; i <= totalPage; i++) {
					 			if (pageNo == i) {
					 				document.write('<option value="' + i + '" selected="selected">' + i + '</option>');
					 			} else {
					 				document.write('<option value="' + i + '">' + i + '</option>');
					 			}
					 		}
					 	</script>
					 </select>页
					,共${pageModel.totalPage }页&nbsp;
					<a href="javascript:submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerifyByPage&pageNo=${pageModel.next}')">下一页</a>&nbsp;
					<a href="javascript:submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerifyByPage&pageNo=${pageModel.last}')">尾页</a>&nbsp;
					共${pageModel.allRecords }条记录
				</td>
			</tr>
		</tbody>
	</table>
</div>
</body>
<script src="<%=request.getContextPath() %>/static/comm/plugin/jquery.min.js"></script>
<script src="<%=request.getContextPath() %>/static/comm/plugin/layer/layer.js"></script>
<script src="<%=request.getContextPath() %>/static/comm/plugin/bootstrap/js/bootstrap.min.js"></script>
<script src="<%=request.getContextPath() %>/static/comm/plugin/toastr/toastr.js"></script>
<script src="<%=request.getContextPath() %>/static/company/js/my97datapicker/WdatePicker.js"></script>
<script>
	/**
	 * 信息提示框
	 */
	toastr.options = {
	  "closeButton": true,
	  "debug": false,
	  "positionClass": "toast-top-right",
	  "onclick": null,
	  "showDuration": "300",
	  "hideDuration": "1000",
	  "timeOut": "3000",
	  "extendedTimeOut": "1000",
	  "showEasing": "swing",
	  "hideEasing": "linear",
	  "showMethod": "fadeIn",
	  "hideMethod": "fadeOut"
	}
	if ('${success }') {
		toastr.success('${success }');
	}
	if ('${error }') {
		toastr.error('${error }');
	}
	
	/**
	 * 审核
	 */
	 function verify(applicationId, pageNo) {
	    //询问框
	    layer.confirm('通过还是拒绝？', {
	    	closeBtn: 0,
	        icon : 3,
	        btn: ['通过','拒绝'] //按钮
	    }, function(){
	        layer.msg('您选择了通过！', {icon: 1, time: 1000});
	        location = '<%=request.getContextPath()%>/ApplicationServlet?command=verify&status=2&applicationId=' + applicationId + '&pageNo=' + pageNo;
	    }, function(){
	        layer.msg('您选择了拒绝！', {icon: 2, time: 1000});
	        location = '<%=request.getContextPath()%>/ApplicationServlet?command=verify&status=3&applicationId=' + applicationId + '&pageNo=' + pageNo;
	    });
	}
		
	/**
	 * 跳转到指定的页数
	 */
	function goPage(obj) {
		submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerifyByPage&pageNo=' + obj.value);
	}
	
	/**
	 * 分页时，使用JS使用表单
	 */
	function submitForm(url) {
		var conditionForm = document.getElementById('conditionForm');
		conditionForm.action = url;
		conditionForm.submit();
	}
	/**
	* AJAX简历删除
	*/
	function del(obj, positionId) {
    			/* 
	    			// 创建XMLHttpRequest。我在页面上不动，我准备委托一个人去帮我删除数据
	    			var xmlhttp;
					if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					  xmlhttp=new XMLHttpRequest();
					} else { // code for IE6, IE5
					  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
					
	    			// XMLHttpRequest请求。我把这个人派出去 
	    			xmlhttp.open('GET', '<%=request.getContextPath()%>/PositionServlet?command=delete&positionId=' + positionId + '&time=' + new Date().getTime(), true);
					xmlhttp.send();
	    			
					// 随时与这个人保持联系，方便及时知道结果
					xmlhttp.onreadystatechange=function() {
			    	  // XMLHttpRequest响应。这个人把事情做完了（删除数据），然后回来告诉我
					  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					    var text = xmlhttp.responseText;
					    // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
					    if (text == 'fail') {
					    	layer.msg('操作失败！', {time: 2000, icon: 5});
					    } else {
					    	layer.msg('操作成功！', {time: 2000, icon: 6});
					    	$(obj.parentNode.parentNode).remove();
					    }
					  }
					}
    		  */
    		  
    		  // $.get(url, function(data) {})

    		  $.get('<%=request.getContextPath()%>/PositionServlet?command=delete&positionId=' + positionId + '&time=' + new Date().getTime(), function(text){
			     // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
			     if (text == 'fail') {
			    	layer.msg('操作失败！', {time: 2000, icon: 5});
			     } else {
			    	layer.msg('操作成功！', {time: 2000, icon: 6});
			    	$(obj.parentNode.parentNode).remove();
			     }
    		  });
    		}
</script>
</html>
